package user

import (
	"context"
	"net/http"
)

type Service interface {
	// 用户登录
	Login(context.Context, *LoginRequest) (*Session, error)
	// 用户登出
	Logout(context.Context, *LogoutRequest) error
}

func NewLoginRequest() *LoginRequest {
	return &LoginRequest{}
}

func NewLoginRequestFromBasicAuth(r *http.Request) *LoginRequest {
	user, pass, _ := r.BasicAuth()
	return &LoginRequest{
		Name: user,
		Pass: pass,
	}
}

type LoginRequest struct {
	Name string
	Pass string
}

// 对象,对象是具体的类实例化出来的
func NewLogoutRequest() *LogoutRequest {
	return &LogoutRequest{}
}

// 类
type LogoutRequest struct {
	Username string `json:"username"`
}
